package org.rescue;

import java.util.Properties;
import org.apache.commons.configuration.*;


import org.rescue.data.extraction.*;
import org.rescue.data.extraction.gate.*;
import org.rescue.search.*;

public class Diamond {

	/**
	 * Demonstration of basic Diamond search, extraction, classification.
	 * @param args
	 */
	public static void main(String[] args) {


		// search parameters 
		String q = "hurricane katrina -site:wikipedia.org";
		int max = 2;
		

		try {
			
			// get system-specific information from diamond.properties 
			// which should be included in the classpath
			Configuration config = new PropertiesConfiguration("diamond.properties");			
			
			// set java property with location of GATE files for extraction
			Properties p = new Properties(System.getProperties());
			p.setProperty("gate.home", config.getString("gate.home"));
			System.setProperties(p);			
								

			
			// configure how a new dataset will be created 
			Dataset d = new Dataset();
			d.setSearchBehavior(new SearchGoogle());
			d.setQuery(q);
			d.setExtractBehavior(new ExtractGATE());
			d.setClassifyBehavior(new ClassifySimpleLocation());			

			// actually build the dataset
			d.performSearch(max);
			d.performExtraction();
			d.performClassification();
						
			// save the dataset in the database
			DatasetDB datasetDB = new DatasetDB();
			datasetDB.writeDataset(d);
				
			
			
		}
		catch (ConfigurationException ce) {
			System.out.println("Error opening diamond.properties configuration file:");
			System.out.println(ce.getMessage());
			
		}	
		catch (SearchException se) {
			System.out.println("Error performing the search:");
			System.out.println(se.getMessage());
			System.out.println(se.getErrorDetail());	
		}
		
		

	}
}
